//
//  HRZCartService.m
//  EMarket
//
//  Created by 石头 on 2018/7/17.
//  Copyright © 2018 好日子. All rights reserved.
//

#import "HRZCartService.h"

// Controllers

// Models
#import "HRZAddShopCartModel.h"
#import "HRZUpdateNumberModel.h"
#import "HRZDeleteCarModel.h"
#import "HRZGetShopCarListModel.h"
#import "HRZCartGoodsDetailModel.h"
// Views

// Vendors

// Categories

// Others

@interface HRZCartService ()

@end


@implementation HRZCartService

+ (void)addGoodsToCartWith:(HRZAddShopCartModel *)model
                   success:(void (^)(NSString *))success
                   failure:(void (^)(NSString *))failure {
    NSMutableDictionary *params = [model mj_keyValues];
    HRZAPIRequest *request = [[HRZAPIRequest alloc] initWithAPIRequestType:kAPIRequestType_Post withSubPath:kCartAddGoodsUrl];
    request.params = params;
    [HRZAPIClient execute:request];
    
    request.ServerSuce = ^(NSDictionary *sucObj) {
        success(@"");
    };
    
    request.ServerFail = ^(NSString *error) {
        failure(error);
    };
}

+ (void)getAllCartGoodsWithCurrentUserId:(HRZGetShopCarListModel *)model
                                 success:(void (^)(NSArray<HRZCartGoodsDetailModel *> *))success
                                 failure:(void (^)(NSString *))failure{
    
    NSMutableDictionary *params = [model mj_keyValues];
    HRZAPIRequest *request = [[HRZAPIRequest alloc] initWithAPIRequestType:kAPIRequestType_Get withSubPath:kCartGoodsListUrl];
    request.params = params;
    [HRZAPIClient execute:request];
    
    request.ServerSuce = ^(NSDictionary *sucObj) {
        NSArray *array = [HRZCartGoodsDetailModel mj_objectArrayWithKeyValuesArray:sucObj];
        success(array);
    };
    
    request.ServerFail = ^(NSString *error) {
        failure(error);
    };
}

+ (void)updateCartGoodsNunberWith:(HRZUpdateNumberModel *)model
                          success:(void (^)(NSString *))success
                          failure:(void (^)(NSString *))failure {
    NSMutableDictionary *params = [model mj_keyValues];
    HRZAPIRequest *request = [[HRZAPIRequest alloc] initWithAPIRequestType:kAPIRequestType_Post withSubPath:kCartUpdateGoodsUrl];
    request.params = params;
    [HRZAPIClient execute:request];
    
    request.ServerSuce = ^(NSDictionary *sucObj) {
        success(@"");
    };
    
    request.ServerFail = ^(NSString *error) {
        failure(error);
    };
}

+ (void)deletedGoodsFromCart:(HRZDeleteCarModel *)model
                     success:(void (^)(NSString *))success
                     failure:(void (^)(NSString *))failure {
    
    NSMutableDictionary *params = [model mj_keyValues];
    HRZAPIRequest *request = [[HRZAPIRequest alloc] initWithAPIRequestType:kAPIRequestType_Post withSubPath:kCartDeletedGoodsUrl];
    request.params = params;
    [HRZAPIClient execute:request];
    
    request.ServerSuce = ^(NSDictionary *sucObj) {
        success(@"");
    };
    
    request.ServerFail = ^(NSString *error) {
        failure(error);
    };
}

@end
